package com.learn.training.multithread.chapter6.minchapter4.demo1;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Counter {
    private int count = 0;
    private final Lock lock = new ReentrantLock();

    public void add(int n){
        lock.lock();
        try{
            count += n;
        }finally {
            lock.unlock();
        }
    }

    public void dec(int n){
        lock.lock();
        try{
            count -=n;
        }finally {
            lock.unlock();
        }
    }

    public int get(){
        return count;
    }
}
